package btc.backend.servicios;

import btc.backend.process.ConnectionFactory;
import btc.model.Bloque;
import btc.model.Maquina;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * User: juan
 * Date: 11/27/12
 * Time: 11:14 PM
 */
public class MaquinaAppl {

    public static List<Maquina> obtenerMaquinas() {
        List<Maquina> maquinas = new ArrayList<Maquina>();
        try {

            PreparedStatement getMaquinasSt = ConnectionFactory.getConnection().
                    prepareStatement("select ID, DESCRIPCION, UBICACION from maquina");

            ResultSet r = getMaquinasSt.executeQuery();

            while(r.next()){
                Maquina maquina = new Maquina(r.getInt(1), r.getString(2), r.getString(3));
                maquinas.add(maquina);
            }
            r.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }

        return maquinas;
    }
}
